import { computed, ref } from 'vue'
import { defineStore } from 'pinia'
import { buildMenuTree } from '@/router/routerHandler'

export const useMenuStore = defineStore(
  'menu',
  () => {
    const allRoutesFlat = ref([])

    const allRoutesTree = computed(() => {
      return buildMenuTree(allRoutesFlat.value)
    })

    const tabbarList = ref([])

    const keepAliveList = ref([])

    return {
      allRoutesFlat,
      allRoutesTree,
      tabbarList,
      keepAliveList,
    }
  },
  {
    persist: {
      pick: ['tabbarList'],
    },
  }
)
